using UnityEngine;

public static class TransformHelpr
{
    public static float ForwardOrBack(this Transform t,Vector3 targetPostion)
    {
        Vector3 dir = targetPostion - t.position;
        float v = Vector3.Dot(t.forward,dir); //点乘
        return v; //大于0 在前方 小于0在后方
    }

    public static float SameForward(this Transform t, Vector3 targetForward)
    {
        //Vector3 dir = targetPostion - t.position;
        float v = Vector3.Dot(t.forward, targetForward); //点乘
        return v; //大于0 相同朝向 小于0相反朝向
    }


    public static float Angle(this Transform t, Vector3 targetPostion)
    {
        Vector3 dir = (targetPostion - t.position).normalized;

        Vector3 crossResult = Vector3.Cross(t.forward, dir);

        float v = Vector3.Angle(t.forward, dir);
        if (crossResult.y > 0)  //反面
        {
            return 360 - v;
        }
        else
        {
            return v;
        }
    }
}